#ifndef ACUASUART_H
#define ACUASUART_H
/**
 @defgroup ACUAS_EPuart ACUAS Easy Programming UART
 @brief C macros to easily program UART of the ACUAS ATmega16/ATmega32 board.
 @author Thomas Siepmann, Aachen University of Applied Sciences, Germany. Based on the UART library of Peter Fleury http://jump.to/fleury
 @see http://www.siepmann.fh-aachen.de
*/

#ifndef UART_BAUD_RATE
/// default baud rate
#define UART_BAUD_RATE 1200
#endif

#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "UART\uart.h"

/*@{*/

/// @file ACUASUART.h
/// @file ACUASUART.c

/// Global Variable used by UART_NUMBER to store the alphanumeric representation of the number
unsigned char uart_str[21];

void uart_read_line(unsigned char * c_array, uint8_t max, int try_sec);

/// Initialises the UART. Must be invoked in the PROGRAM_INIT part. Sets frame format: asynchronous, 8 data bits, no parity, 1 stop bit
#define INIT_UART {uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); sei();}
/// Sends a string which is located in SRAM over UART
#define UART_TEXT(string) uart_puts((char*) string);
/// Sends a string which is located in flash ROM over UART. The string must be declared as: static const char PText[] PROGMEM = "text"
#define UART_TEXT_CONST(string) uart_puts_p(string);
/// Sends a number over UART
#define UART_NUMBER(x) {itoa( x, (char*)uart_str, 10); uart_puts((char*)uart_str);}
/// Sends one character over UART
#define UART_CHAR(c) uart_putc(c);
/// Sends a linefeed over UART
#define UART_CRLF uart_putc(13); uart_putc(10);
/// Reads one character from UART
#define UART_READ_CHAR(c) c = uart_getc();
///
/**
 *  @brief   Reads one line of text delimeted by a carriage return (ASCII 13). The function waits until a carriage return is received or max_char characters have been received
 *  @param   c_array a char-array which can contain at least max_char characters + 1
 *  @param   max_char the maximum amount of characters which are received if no carriage return is received.
 *  @return  none
 */
#define UART_READ_LINE(c_array,max_char) uart_read_line((c_array), (max_char), 3);

/*@}*/
#endif // ACUASUART_H
